import java.awt.Canvas;
import java.awt.Color;
//import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
//import java.awt.Dimension;
import java.awt.GridLayout;
//import java.awt.Panel;
//import java.awt.Window;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.event.MouseAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class ColorPanel extends Panel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6962122414231741740L;
	Color color = Color.black;
	Canvas c;
	Canvas cans[] = { new Canvas(),new Canvas(),new Canvas(),new Canvas(),new Canvas(),
						new Canvas(),new Canvas(),new Canvas(),new Canvas(),new Canvas(),new Canvas(),new Canvas() };
	Color colors[] = {Color.BLACK,Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.RED, Color.ORANGE,
			Color.MAGENTA, Color.PINK, Color.GREEN, Color.YELLOW, Color.BLUE, Color.CYAN}	;


	ColorPanel() {
		super();
		//setSize(80, 100);
		setLayout(new GridLayout(2,1));
		//setLayout(new GridBagLayout());
		c = new Canvas();
		c.setBackground(color);
		c.setSize(20,20);
		
		Panel col = new Panel();
		Panel sel = new Panel();
		
		//setLayout(new GridLayout(2,1));
		
		sel.add(new Label("Color"));
		sel.add(c);
		
		
		col.setLayout(new GridLayout(3, 4));
		this.add(sel);
		this.add(col);
		
		
		
		for(int i = 0; i< cans.length; i++){
			cans[i].setBackground(colors[i]);
			col.add(cans[i]);
			cans[i].setSize(20,20);
			cans[i].addMouseListener(new MouseAdapter(){
				public void mouseClicked(MouseEvent e) {
					color = e.getComponent().getBackground();
					c.setBackground(color);
				}
			});
		}
	}


	public Color getColor() {
		return color;
	}
}
